package com.example.navigationdemo;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


public class SecondFragment extends Fragment {


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_second, container, false);

        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        Bundle arg = getArguments();
        if (arg != null) {
            // 传统方式接受参数
//            int age = arg.getInt("age");
//            String name = arg.getString("name");
//            Log.d("aaaa", "age: " + age + "==========name:" + name);

            //safeargs 接受参数
            String name1 = MainFragmentArgs.fromBundle(arg).getName();
            int age1 = MainFragmentArgs.fromBundle(arg).getAge();

            Log.d("aaaa", "age: " + age1 + "==========name:" + name1);
        }
    }
}